# -*- coding: UTF-8 -*-

# from sklearn.metrics import confusion_matrix
# y_true = [1, 0, 1, 1, 0, 0]
# y_pred = [0, 1, 1, 0, 1, 1]
# cm = confusion_matrix(y_true, y_pred)
# print(cm)
# tn, fp, fn, tp = cm.ravel()
# print("tn:{}, fp:{}, fn:{}, tp:{}".format(tn, fp, fn, tp))

#################################################################
# 可视化混淆矩阵
import numpy as np
import matplotlib.pyplot as plt

font1 = {'family': 'Times New Roman',
        'size':'15',}
cm = np.array([[396947., 127.], 
                [113., 6813.]])
plt.matshow(cm)
plt.colorbar()
plt.xlabel('prediction', font1)
plt.ylabel('true', font1)
plt.xticks(np.arange(cm.shape[1]), list(range(2)))
plt.yticks(np.arange(cm.shape[1]), list(range(2)))
plt.show()

#################################################################

# import numpy as np

# import matplotlib.pyplot as plt

# from sklearn import metrics


# # 计算roc和auc

# y_score = [ 9.9851e-01,9.9997e-01,1.0000e+00,1.0000e+00,9.9711e-01,

# 9.9997e-01,9.9913e-01,8.4129e-05,9.9940e-01,9.9549e-01,

# 6.3709e-03,9.9890e-01,2.8921e-02,9.9298e-01,9.9845e-01,

# 1.2955e-03,1.0470e-05,5.0030e-04,1.0792e-04,9.9993e-01,

# 6.8361e-01,9.9999e-01,9.3790e-01,8.4222e-01,1.0000e+00,

# 3.7036e-03,9.9920e-01,6.8316e-01,2.6265e-14,9.9859e-01,

# 6.4708e-02,1.0000e+00,9.8933e-01,7.2793e-05,9.9987e-01,

# 1.2028e-04,1.0000e+00,1.8870e-07,9.9999e-01,1.0000e+00,

# 9.9999e-01,1.0000e+00,1.0000e+00,1.0000e+00,7.8533e-03,

# 1.8890e-04,1.0000e+00,2.5989e-02,9.9999e-01,4.6810e-02,

# 9.9897e-01,1.9922e-04,2.6834e-04,7.1890e-02,6.4201e-01,

# 1.1148e-01,6.1339e-06,1.1345e-01,8.6041e-01,1.7573e-02,

# 6.1877e-01,1.0000e+00,8.6309e-01,1.0000e+00,1.9857e-01,

# 1.0000e+00,9.9999e-01,4.7447e-04,9.9927e-01,1.0522e-06,

# 9.9999e-01,1.0000e+00,6.0466e-07,1.0000e+00,4.3941e-05,

# 4.1809e-02,3.4526e-09,1.6633e-07,8.3515e-07,9.9989e-01,

# 4.0750e-01,5.4201e-08,1.3404e-09,1.6206e-03,3.2980e-01,

# 2.1062e-06,3.2605e-03,9.9847e-01,7.6638e-07,9.6480e-01,

# 1.2248e-05,6.0582e-01,9.9997e-01,9.9997e-01,2.1907e-04,

# 3.1958e-01,2.6135e-02,1.4250e-01,9.0930e-06,3.6019e-05,

# 1.0000e+00,8.2119e-01,2.2820e-02,9.9970e-01,2.2836e-06,

# 2.1747e-01,1.2492e-06,6.6268e-01,9.4269e-01,9.9999e-01,

# 6.0224e-01,1.0339e-04,4.6033e-01,9.9127e-01,2.1745e-02,

# 2.7529e-05,5.1265e-01,4.0928e-03,1.0000e+00,2.2949e-05,

# 9.9689e-01,9.8733e-01,6.9968e-05,1.2510e-13,9.2999e-01,

# 5.2054e-05,4.0495e-02,2.6996e-06,9.9880e-01,9.8693e-01,2.9835e-01,9.9989e-01,8.4126e-03,

# 6.8882e-05,8.8586e-03,1.0000e+00,6.1230e-10,9.9997e-01,

# 1.0000e+00,1.7148e-08,1.0000e+00,6.7212e-06,1.1449e-05,

# 4.8784e-02,1.0000e+00,2.6514e-06,1.0000e+00,8.8992e-08,

# 6.4772e-08,4.0303e-07,1.7111e-08,7.1858e-08,8.2972e-08,

# 9.9997e-01,1.0000e+00,1.0000e+00,1.0000e+00,1.0000e+00,

# 1.0000e+00,1.6598e-08,9.9999e-01,4.4640e-09,8.1506e-01,

# 8.1549e-05,6.6065e-05,1.8652e-09,2.3904e-13,9.9978e-01,

# 1.0000e+00,1.0000e+00,4.3819e-12,1.0000e+00,9.9985e-01,

# 9.9969e-01,3.9544e-06,9.9999e-01,1.0000e+00,1.0000e+00,

# 9.9962e-01,5.4252e-12,9.9999e-01,3.1807e-09,1.0000e+00,

# 2.7246e-06,1.0000e+00,3.4905e-06,2.9352e-05,1.0000e+00,

# 9.8905e-06,9.9999e-01,1.0000e+00,4.3435e-08,1.0000e+00,

# 3.2698e-06,1.0000e+00,6.1964e-08,9.9998e-01,1.1808e-08,

# 1.0000e+00,1.3313e-09,1.0000e+00,9.1215e-05,1.0000e+00,

# 9.9999e-01,1.8799e-05,1.4784e-09,1.0000e+00,2.1517e-09,

# 7.4920e-09,1.0000e+00,7.0349e-08,6.6840e-09,1.0000e+00,

# 1.5083e-09,9.9997e-01,1.1912e-07,1.4259e-11,9.9990e-01,

# 4.8948e-06,1.0000e+00,3.7790e-07,1.0000e+00,5.2548e-05,

# 1.0000e+00,9.8434e-07,8.0895e-01,3.1273e-02,1.9782e-05,

# 9.9975e-01,1.0000e+00,2.5450e-07,3.4767e-07,1.0000e+00,

# 1.0000e+00,1.0000e+00,4.6116e-05,1.0000e+00,3.2100e-05,

# 2.5731e-05,1.4733e-07,1.0000e+00,1.0000e+00,1.0000e+00,

# 1.1246e-06,2.4184e-04,1.0000e+00,1.0000e+00,4.1336e-10,

# 1.0000e+00,3.1744e-05,9.9999e-01,1.0000e+00,1.0544e-06,

# 2.4347e-06,9.9991e-01,6.7946e-10, 1.0000e+00,7.5963e-08,1.0000e+00,1.3206e-07,9.9998e-01,

# 7.1259e-11,1.0000e+00,2.1090e-01,1.0000e+00,1.0000e+00,

# 5.8330e-01,1.0000e+00,9.9998e-01,4.8566e-07,1.0000e+00,

# 3.9619e-06,1.0000e+00,1.0000e+00,1.6349e-07,1.8042e-06,

# 9.9966e-01,8.6250e-07,1.0000e+00,1.0000e+00,1.0000e+00,

# 1.0000e+00,1.0000e+00,9.9999e-01,8.8150e-01,1.1298e-07,

# 2.6820e-06,9.9253e-01,6.0419e-08,9.9927e-01,1.0000e+00,

# 1.5348e-06,1.0000e+00,9.9974e-01,4.4206e-08,1.0000e+00,

# 1.0000e+00,1.0000e+00,1.0000e+00,2.6568e-06,9.9999e-01,

# 1.0000e+00,3.3616e-06,9.9996e-01,6.1177e-04,2.7520e-04,

# 1.0000e+00,1.0000e+00,1.0000e+00,9.9998e-01,2.9589e-09,

# 9.9914e-01,1.0000e+00,7.5814e-06,1.0000e+00,9.8563e-01,

# 5.7107e-10,1.0000e+00,2.9358e-05,9.9816e-01,7.6606e-05,

# 1.0000e+00,1.2098e-05,2.0024e-10,1.0000e+00,7.8922e-07,

# 9.9997e-01,4.5417e-04,9.9998e-01,2.1048e-12,9.9998e-01,

# 1.0000e+00,1.0000e+00,1.0000e+00,1.0000e+00,2.5177e-05,

# 7.7803e-10,9.9999e-01,1.0000e+00,1.0000e+00,1.0000e+00,

# 1.0000e+00,1.0000e+00,1.0000e+00,1.0000e+00,8.2414e-01,

# 1.0000e+00,3.1679e-10,9.9999e-01,3.3770e-09,9.9999e-01,

# 4.5487e-07,8.3379e-01,1.0000e+00,1.0000e+00,1.0000e+00,

# 1.0000e+00,1.0000e+00,9.9990e-01,1.4393e-09,9.9999e-01,

# 9.9996e-01,9.9992e-01,1.0000e+00,1.0000e+00,1.0000e+00,

# 5.1302e-07,3.6753e-09,1.0000e+00,1.0000e+00,7.2734e-08,

# 5.8410e-05,9.9995e-01,8.5471e-07,1.0000e+00,1.0000e+00,

# 2.9306e-01,1.0000e+00,4.7422e-06,1.7867e-03,1.0000e+00,

# 1.0000e+00,6.0311e-09,1.0000e+00, 1.0000e+00,8.4827e-09,1.0000e+00,1.0000e+00,5.4047e-09,

# 1.7192e-07,9.9988e-01,9.2511e-08,1.0000e+00,1.0000e+00,

# 1.0000e+00,7.8191e-08,1.0000e+00,1.0000e+00,1.0000e+00,

# 2.4809e-06,1.0000e+00,7.0371e-09,6.5127e-12,9.8816e-01,

# 1.0000e+00,7.0720e-07,1.0000e+00,1.0000e+00,9.9999e-01,

# 9.9998e-01,1.0000e+00,1.0000e+00,1.0000e+00,3.4725e-10,

# 1.9239e-06,9.9886e-01,5.8176e-08,1.7001e-06,1.0000e+00,

# 6.2994e-04,1.0000e+00,1.2081e-04,6.2985e-09,1.0000e+00,

# 4.8864e-07,1.0000e+00,8.6360e-11,1.0000e+00,3.9228e-08,

# 2.0253e-07,1.0000e+00,1.0000e+00,3.2947e-07,7.0709e-12,

# 9.9952e-01,1.0000e+00,1.0000e+00,1.0000e+00,1.0000e+00,

# 1.8704e-05,3.9649e-08,1.0000e+00,1.0000e+00,4.8392e-06,

# 1.0000e+00,1.1054e-10,1.0000e+00,5.9257e-16,1.6800e-04,

# 1.0000e+00,3.4565e-06,1.0000e+00,1.0249e-05,6.3914e-05,

# 1.0000e+00,7.1082e-11,2.4418e-12,9.9982e-01,9.9999e-01,

# 3.4777e-03,9.9999e-01,2.4618e-10,1.0000e+00,6.3010e-09,

# 1.0416e-09,9.9058e-01,1.0000e+00,3.2960e-05,5.1490e-13,

# 1.0000e+00,1.0000e+00,2.3734e-04,3.2588e-07,1.0000e+00,

# 1.4779e-06,1.0000e+00,2.3104e-10,9.9998e-01,9.9999e-01,

# 2.9136e-10,9.9999e-01,1.3683e-08,1.7976e-07,9.9983e-01,

# 3.1666e-06,4.1248e-06,8.4381e-07,9.9998e-01,3.6832e-06,

# 3.8006e-06,9.9983e-01,1.0000e+00,6.7821e-08,1.3557e-08,

# 1.0000e+00,1.0000e+00,7.9802e-03,1.0000e+00,9.8945e-01,

# 2.4669e-04,1.0000e+00,7.4492e-07,1.0000e+00,1.3954e-02,

# 1.0000e+00,1.0846e-07,9.6761e-11,1.0000e+00,1.0000e+00,

# 2.7915e-06,3.6568e-08,6.9262e-08, 2.5593e-06,1.1284e-11,1.3780e-01,1.0000e+00,7.9982e-06,

# 2.5574e-08,9.9837e-01,6.1947e-08,9.9978e-01,4.3517e-11,

# 1.0000e+00,1.0538e-08,1.0000e+00,5.9406e-10,1.0000e+00,

# 1.0000e+00,5.5782e-09,2.4304e-10,1.0000e+00,1.0000e+00,

# 4.8344e-09,1.0000e+00,3.1077e-13,2.2091e-05,8.2426e-02,

# 3.6654e-11,7.6557e-08,6.3855e-11,1.0000e+00,1.0000e+00,

# 1.5186e-10,3.9777e-11,1.0000e+00,1.0000e+00,9.9975e-01,

# 1.6044e-10,3.1784e-09,9.9911e-01,5.4308e-07,1.0000e+00,

# 1.0000e+00,1.9014e-11,1.0000e+00,3.9231e-06,3.1050e-07,

# 1.0000e+00,2.7031e-05,1.0000e+00,9.8138e-01,1.0000e+00,

# 1.8816e-09,9.9999e-01,1.0000e+00,6.7595e-08,1.3619e-08,

# 9.9888e-01,4.1556e-07,1.2928e-12,1.0000e+00,9.9918e-01,

# 4.5048e-06,9.9991e-01,5.0555e-10,8.0632e-11,9.9990e-01,

# 9.8021e-10,1.2623e-08,9.8738e-01,1.2176e-06,1.0000e+00,

# 1.0000e+00,5.0820e-08,9.3541e-01,8.0202e-09,1.0000e+00,

# 1.1401e-07,3.5547e-10,2.7973e-02,6.2540e-01,1.5087e-10,

# 1.3505e-09,2.6094e-07,5.2484e-09,6.3256e-07,7.8440e-07,

# 1.0000e+00,5.0651e-10,1.4844e-09,6.4393e-11,1.0000e+00,

# 3.4127e-10,1.0000e+00,1.4658e-04,1.0000e+00,3.2133e-06,

# 5.5449e-02,9.9992e-01,6.5473e-07,1.0000e+00,9.7145e-08,

# 1.0000e+00,1.0000e+00,9.1511e-07,9.9960e-01,4.6388e-08,

# 9.1321e-06,9.9934e-01,2.0286e-08,1.0000e+00,7.6241e-09,

# 1.0000e+00,6.0771e-06,9.9995e-01,2.0597e-06,1.0000e+00,

# 9.9999e-01,2.0370e-07,1.0000e+00,1.0000e+00,4.4022e-09,

# 7.7162e-06,1.0000e+00,1.0000e+00,9.9999e-01,9.1957e-10,

# 9.9600e-01,2.3197e-09,1.0000e+00, 6.2079e-10,4.3248e-06,1.0000e+00,1.0662e-08,9.9996e-01,

# 1.0000e+00,2.8324e-11,5.4074e-13,1.0000e+00,1.8376e-09,

# 1.0000e+00,1.0000e+00,1.0000e+00,5.6099e-07,1.0000e+00,

# 3.1398e-06,1.8213e-11,1.0000e+00,1.8683e-10,5.3258e-12,

# 1.1874e-08,1.0000e+00,2.1775e-09,9.9876e-01,1.0000e+00,

# 1.1038e-07,9.9630e-01,1.0000e+00,1.0000e+00,9.9991e-01,

# 9.9993e-01,1.0000e+00,9.9994e-01,1.0000e+00,1.0000e+00,

# 9.8513e-01,1.0000e+00,9.9991e-01,1.0000e+00,1.0000e+00,

# 9.9998e-01,1.0000e+00,9.0598e-01,1.0000e+00,1.0000e+00,

# 9.9997e-01,1.0000e+00,9.9998e-01,1.0000e+00,1.0000e+00,

# 1.0000e+00,1.9014e-04,9.8399e-01,9.9997e-01,9.9830e-01,

# 9.4997e-01,9.9999e-01,9.9586e-01,1.6980e-05,9.5872e-01,

# 6.8015e-01,1.7353e-06,9.9997e-01,9.0243e-01,9.9999e-01,

# 4.9356e-02,7.9772e-01,9.8660e-09,2.1493e-03,9.6290e-01,

# 1.0022e-02,2.0648e-04,1.0000e+00,4.3441e-10,9.9997e-01,

# 1.0000e+00,9.9972e-01,3.7952e-01,9.9616e-01,1.0000e+00,

# 1.3085e-07,7.1047e-07,9.9999e-01,1.0000e+00,2.1096e-01,

# 2.1710e-01,9.9999e-01,1.0000e+00,3.2707e-09,9.9998e-01,

# 9.5695e-01,1.0000e+00,9.9993e-01,1.0000e+00,9.3975e-04,

# 1.0000e+00,1.5765e-03,1.0000e+00,5.0613e-03,9.7049e-01,

# 9.9994e-01,9.9312e-01,3.1691e-05,1.0073e-07,5.0117e-03,

# 9.6510e-01,5.0843e-01,2.7408e-05,2.4712e-05,2.0924e-01,

# 3.5439e-02,3.3662e-02,1.0000e+00,1.0000e+00,2.2658e-01,

# 9.9968e-01,1.0000e+00,9.9977e-01,9.9984e-01,3.4074e-06,

# 2.7410e-06,1.0000e+00,1.0000e+00,6.6023e-07,4.9228e-07,

# 9.9869e-01,9.1091e-02,1.1663e-07, 1.4192e-09,1.5327e-05,7.4474e-06,4.8801e-01,6.4667e-04,

# 2.3570e-03,1.0504e-03,8.9965e-01,7.3365e-01,2.1573e-10,

# 8.4996e-01,3.2954e-03,9.9890e-01,6.3002e-04,8.4769e-01,

# 2.3065e-03,9.9984e-01,6.1653e-03,1.8803e-02,5.6274e-02,

# 1.1619e-05,3.9471e-11,7.8479e-01,1.7970e-03,1.0000e+00,

# 5.5835e-01,9.9999e-01,1.6650e-07,8.7065e-02,1.8843e-07,

# 1.8546e-02,2.7420e-02,4.3483e-01,1.0000e+00,6.8027e-01,

# 3.7601e-04,6.4353e-02,9.2600e-01,9.9945e-01,9.7244e-01,

# 9.9993e-01,2.8215e-03,2.3968e-04,1.0000e+00,9.9958e-01,

# 7.6044e-09,5.5400e-01,7.0238e-11,3.5212e-08,8.3071e-07,

# 2.4510e-05,9.9999e-01,9.9980e-01,9.9998e-01,2.8390e-02,

# 1.4055e-06,9.1803e-10,1.0000e+00,3.1567e-06,2.5945e-05,

# 9.9999e-01]

# y_test = [ 1,1,1,1,1,1,1,0,1,1,0,1,1,1,

# 1,1,0,0,0,1,0,1,0,1,1,0,1,1,

# 0,1,0,1,1,0,1,0,1,0,1,1,1,1,

# 1,1,0,0,1,0,1,0,1,0,0,0,1,1,

# 0,0,1,0,1,1,1,1,0,1,1,0,1,0,

# 1,1,0,1,0,0,0,0,0,0,1,1,0,0,

# 1,0,0,1,0,1,0,0,1,0,0,1,0,1,

# 0,0,1,0,0,1,0,0,0,0,0,1,0,0,

# 1,1,0,0,1,0,1,0,1,1,0,0,1,0,

# 0,0, 1,0,0,1,0,0,0,1,0,1,1,0,1,0,

# 0,1,1,0,1,0,0,0,0,0,0,1,1,1,

# 1,1,1,0,1,0,1,0,0,0,0,1,1,1,

# 0,1,1,1,0,1,1,1,1,0,1,0,1,0,

# 1,0,0,1,0,1,1,0,1,0,1,0,1,0,

# 1,0,1,0,1,1,0,0,1,0,0,1,0,0,

# 1,0,1,0,0,1,0,1,0,1,0,1,0,1,

# 0,0,1,1,0,0,1,1,1,0,1,0,0,0,

# 1,1,1,0,0,1,1,0,1,0,1,1,0,0,

# 1,0,1,0,1,0,1,0,1,0,1,1,1,1,1,0,

# 1,0,1,1,0,0,1,0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,1,1,0,0,0,0,1,1,0,0,1,0,1,

# 1,1,0,1,1,1,1,0,0,1,1,0,0,1,

# 0,0, 0,0,0,1,1,0,0,1,0,0,1,0,1,0,

# 0,0,1,0,1,0,1,0,0,0,1,0,1,0,

# 0,0,0,0,0,1,1,0,0,1,0,1,1,0,

# 0,1,1,0,1,0,0,0,0,1,0,1,0,0,

# 0,1,0,0,1]

# precision, recall, _thresholds = metrics.precision_recall_curve(y_test, y_score)
# # print(precision, recall)

# auc = metrics.auc(recall, precision)

# lw = 2

# plt.figure(figsize=(10,10), facecolor=(1, 1, 1))

# plt.plot(precision, recall, color='darkorange',

# lw=lw, label=' (AUC = %0.2f)' % auc) ###假正率为横坐标，真正率为纵坐标做曲线

# plt.plot([0, 1], [1, 0], color='navy', lw=lw, linestyle='--')

# plt.xlim([0.0, 1.0])

# plt.ylim([0.0, 1.0])

# # 设置刻度字体大小

# plt.xticks(fontsize=15)

# plt.yticks(fontsize=15)

# plt.xlabel('recall', fontsize=20)

# plt.ylabel('precision', fontsize=20)

# #plt.title('Receiver operating characteristic example')

# plt.legend(loc="upper right")

# plt.show()
